package net.wanho.hospital.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import net.wanho.hospital.constant.OrderConstant;
import net.wanho.hospital.po.Arrange;
import net.wanho.hospital.po.Orders;
import net.wanho.hospital.service.OrdersService;
import net.wanho.hospital.vo.AjaxResult;
import org.springframework.web.bind.annotation.*;
import lombok.RequiredArgsConstructor;
import java.io.Serializable;
import java.util.Map;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 汤小洋
 * @since 2023-12-27
 */
@Api(tags = "接口")
@RestController
@RequestMapping("/order")
@RequiredArgsConstructor
public class OrdersController {

    private final OrdersService ordersService;

    @ApiOperation("分页查询")
    @GetMapping("/{pageNum}/{pageSize}")
    public AjaxResult findPage(@ApiParam("当前页") @PathVariable int pageNum,@ApiParam("页大小") @PathVariable int pageSize, Orders orders){
        IPage page = ordersService.findPage(pageNum,pageSize,orders);
        return AjaxResult.success(page);
    }

    @ApiOperation("按主键查询")
    @GetMapping("/{oId}")
    public AjaxResult getById(@ApiParam("学号") @PathVariable Serializable oId){
        return AjaxResult.success(ordersService.getById(oId));
    }


    @ApiOperation("修改")
    @PostMapping("/updateOrder")
    public AjaxResult edit(@RequestBody Orders orders){
        orders.setOState(OrderConstant.STATE_FINISHED);

        ordersService.updateById(orders);
        return AjaxResult.success();
    }

    @ApiOperation("按主键删除")
    @DeleteMapping("/{oId}")
    public AjaxResult removeById(@ApiParam("学号") @PathVariable Serializable oId){
        ordersService.removeById(oId);
        return AjaxResult.success();
    }

    @GetMapping("/findOrderTime")
    public AjaxResult findOrderTime(String arId){
        return AjaxResult.success();
    }

    @GetMapping("/updatePrice")
    public AjaxResult updatePrice(String oId){
        ordersService.updatePrice(oId);
        return AjaxResult.success();
    }

    @GetMapping("/findOrderByDid")
    public AjaxResult findOrderByDid(
            @RequestParam("pageNumber")  int pageNum,
            @RequestParam("size")  int pageSize,
            @RequestParam("dId") Integer dId,
            @RequestParam("query") String pId){
        Map<String,Object> map = ordersService.findOrderByDid(pageNum, pageSize, dId, pId);
        return AjaxResult.success(map);
    }

    @PostMapping("/updateOrderByAdd")
    public AjaxResult updateOrderByAdd(@RequestBody Orders orders){
        ordersService.updateById(orders);
        return AjaxResult.success();
    }

    @GetMapping("/findOrderFinish")
    public AjaxResult findOrderFinish(
            @RequestParam("pageNumber")  int pageNum,
            @RequestParam("size")  int pageSize,
            @RequestParam("dId") Integer dId,
            @RequestParam("query") String pId){
        Map<String,Object> map = ordersService.findOrderFinish(pageNum, pageSize, dId, pId);
        return AjaxResult.success(map);
    }

    @GetMapping("/orderGender")
    public AjaxResult orderGender(){

        return AjaxResult.success();
    }

}
